package com.huifaapp.mall.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.huifaapp.mall.R;
import com.huifaapp.mall.activity.Homefragment.ContentActivity;
import com.huifaapp.mall.bean.ContentBean;

import java.util.List;

/**
 * Created by hello world on 2018/1/25.
 */

public class ContentAdapter extends RecyclerView.Adapter<ContentAdapter.MyViewHolder> {
    List<ContentBean.DataBean> dataBeanList;
    Context context;

    public ContentAdapter(List<ContentBean.DataBean> dataBeanList, Context context){
        this.dataBeanList=dataBeanList;
        this.context=context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.content_item, null);
        MyViewHolder viewHolder=new MyViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.tv.setText(dataBeanList.get(position).getTitle());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context,ContentActivity.class);
                intent.putExtra("content",dataBeanList.get(position).getContent());
                intent.putExtra("title",dataBeanList.get(position).getTitle());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return dataBeanList.size();
    }


    class MyViewHolder extends RecyclerView.ViewHolder{

        private final TextView tv;

        public MyViewHolder(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.content_tv);
        }
    }
}
